package controller;

import javax.validation.Valid;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import form.Account;

@Controller
public class FormController {

	@RequestMapping(value = "firststep", method = RequestMethod.GET)
	public String submitForm(Model model) {
		model.addAttribute("account", new Account());
		return "myform";
	}

	@RequestMapping(value = "form", method = RequestMethod.POST)
	public String submitForm(@Valid Account acc, BindingResult result, Model m) {
		System.out.println(acc.getEmail());
		if (result.hasErrors()) {
			return "myform";
		}

		m.addAttribute("message",
				"Successfully saved person: " + acc.toString());
		return "myform";
	}
}
